Speculative execution is an optimization technique where a computer system performs some task in advance before it is known whether it will be needed in order to prevent any delay that would be incurred by performing the task after it is already known that it is needed. Modern pipelined microprocessors employ speculative execution to reduce the cost of conditional branch instructions using schemes that predict the execution path of a program based on the historical behavior of branch executions. For example, a load instruction can be hoisted above some preceding instructions, including a conditional statement (e.g., if-statement or if-then-else statement), to hide memory access latency. By hoisting the load instruction above the conditional statement, the load corresponding to the load instruction is performed before it is known whether the load will be needed. Such technique of hoisting a load instruction above a conditional statement is referred to as control speculation.
In order to ensure proper program execution when control speculation is employed, the following issues need to be addressed in order to ensure correct program execution: (1) remembering the original place of the load instruction before hoisting; (2) upon performing the speculative load, keeping all the results, including potential exceptions, for some time; (3) disclosing the results of the speculative load to architectural state when control flow passes the original place of the load; and (4) discarding the results of the speculative load if control flow does not pass the original place of the load.